﻿@page "/HostreturnPage"
@inject PickingServer pickingServer
@using System.ComponentModel
@using AntDesign.TableModels
@using ShanjinPDAUI.ModelEntity
@inject ModalService _modalService
@inject MessageService _message
<h3>退/下料</h3>
<div>
    <Row>
        <Col Span="24">请选择主机</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@Machines"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@Machineselet"
                ValueName="@nameof(Machine_Entity.Devid)"
                LabelName="@nameof(Machine_Entity.Remark)">
        </Select>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>宽幅（主机退料需要填写）</label>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Input style="width:100%" Placeholder="Basic usage" @bind-Value="@width" />
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>是否是空卷心</label>
        </Col>
    </Row>
    <Row>
        <Col Span="8" Push="8">
        <Switch style="width:100%" @bind-Value="@Flagempty"></Switch>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <label>是否大卷（主机退料需要选择）</label>
        </Col>
    </Row>
    <Row>
        <Col Span="8" Push="8">
        <Switch style="width:100%" @bind-Value="@Flag"></Switch>
        </Col>
    </Row>
@*
    <Row>
        <Col Span="24">请选择缓存架（缓存架架退料需要选择）</Col>
    </Row>
    <Row>
        <Col Span="24">
        <Select style="width:100%" DataSource="@FullCaches"
                AllowClear="true"
                ValueOnClear="@(0)"
                @bind-Value="@chaneselet"
                ValueName="@nameof(FullCache_Entity.Deviceid)"
                LabelName="@nameof(FullCache_Entity.Remark)">
        </Select>
        </Col>
    </Row>*@
    <br>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat">主机退/下料至于立库</Button>
        </Col>
    </Row>
    <Row>
        <Col Span="24">
        <Button style="width:100%" Type="@ButtonType.Primary" @onclick="@Creat2">主机退/下料至拆包间</Button>
        </Col>
    </Row>
    <br>
</div>

@code {
    ObservableCollection<Machine_Entity> Machines { get; set; } = new ObservableCollection<Machine_Entity>();
    ObservableCollection<FullCache_Entity> FullCaches { get; set; } = new ObservableCollection<FullCache_Entity>();
    int Machineselet { get; set; } = 0;
    bool Flag { get; set; } = false;
    bool Flagempty { get; set; } = false;
    double width;
    int chaneselet { get; set; } = 0;
    protected override async Task OnInitializedAsync()
    {
        var machines = await pickingServer.GetMachine();
        if (machines != null)
        {
            Machines.Clear();
            foreach (var item in machines)
            {
                Machines.Add(item);
            }
        }

        base.OnInitialized();
    }
    private async Task Creat()
    {
        _modalService.Confirm(new ConfirmOptions()
            {
                Title = "提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                var Machine = Machines.FirstOrDefault(x => x.Devid == Machineselet);
                if (Machine != null)
                {
                  //  if (Machine.IsLk)
                   // {
                        //立库领料
                        var b = await pickingServer.HostreturnZJFromLK(Machine, width, Flag);
                        await _message.Info(b);
                   // }
                    //else
                    //{
                    //    //拆包间领料
                    //    if (Machine.UnpackingAre != 0)
                    //    {
                    //        var unpks = await pickingServer.GetuNPK();
                    //        var unpk = unpks.FirstOrDefault(x=>x.Deviceid==Machine.UnpackingAre);
                    //        var b = await pickingServer.HostreturnZJUnpak(Machine, width, unpk, Flag, Flagempty);
                    //        await _message.Info(b);
                    //    }
                    //}
                }

            },
            CancelText = "取消"
        });


    }
    private async Task Creat2()
    {
        _modalService.Confirm(new ConfirmOptions()
            {
                Title = "提示",
                Icon =@<Icon Type="exclamation-circle" Theme="Outline"></Icon>,
            Content = "是否提交？",
            OkText = "确认",
            OnOk = async (e) =>
            {
                var Machine = Machines.FirstOrDefault(x => x.Devid == Machineselet);
                if (Machine != null)
                {
                    //if (Machine.IsLk)
                    //{
                    //    //立库领料
                    //    var b = await pickingServer.HostreturnZJFromLK(Machine, width, Flag);
                    //    await _message.Info(b);
                    //}
                //    else
                  //  {
                        //拆包间领料
                        if (Machine.UnpackingAre != 0)
                        {
                            var unpks = await pickingServer.GetuNPK();
                            var unpk = unpks.FirstOrDefault(x => x.Deviceid == Machine.UnpackingAre);
                            var b = await pickingServer.HostreturnZJUnpak(Machine, width, unpk, Flag, Flagempty);
                            await _message.Info(b);
                        }
                  // }
                }

            },
            CancelText = "取消"
        });


    }
    
}

